package com.woniuxy.hbum.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.woniuxy.hbum.user.dto.UserDto;
import com.woniuxy.hbum.user.service.LoginService;
import com.woniuxy.hbum.user.service.RegisterService;

public class BaseAction extends ActionSupport{
	
	private UserDto baseDTO;

	public UserDto getBaseDTO() {
		return baseDTO;
	}

	public void setBaseDTO(UserDto baseDTO) {
		this.baseDTO = baseDTO;
	}
	public void validateLogin(){
		boolean flag = new LoginService().doLogin(baseDTO);
		if(!flag){
			this.addFieldError("baseError", "登录失败");
		}
	}
	public void validateRegister(){
		boolean flag = new RegisterService().doRegister(baseDTO);
		if(!flag){
			this.addFieldError("baseError", "注册失败");
		}
	}
	public String login(){
		Map map = ActionContext.getContext().getSession();
		map.put("username", baseDTO.getName());
		return "success";
	}
	public String register(){
		return "input";
	}
}
